home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 December / december_2000.iso / Intercd / root / Mail / ^MailShield / setup.exe / data1.cab / Default_Rule_Files / rcptto.mml < prev    next >
Encoding:
Text File  |  2000-10-18  |  5.6 KB  |  157 lines

  1. ##############################################################################
  2. # rcptto.mml 
  3. #
  4. # MailShield script that is run after each SMTP RCPT TO: command
  5. #
  6.  
  7. ##############################################################################
  8. # log this MAIL FROM message
  9. #
  10. #   &LogMessage("SMTP RCPT TO: '".$SmtpRcptTo."'");
  11.  
  12.  
  13. ##############################################################################
  14. # Sleep for a few seconds if more than a certain number of recipients, 
  15. # for each recipient over that limit.  This prevents people who are allowed
  16. # to relay through you from abusing that right and sending thousands
  17. # of recipients through.
  18.  
  19.     if (scalar(@SmtpRcptTo) >= $slow_threshold) {
  20.         &LogMessage("Waiting 2 seconds for recipient number: ".scalar(@SmtpRcptTo), "log_refuse");
  21.         sleep(2);
  22.     };
  23.  
  24.  
  25. ##############################################################################
  26. # Sleep for a number of seconds if we have been instructed to tarpit this connection.
  27.  
  28.     if ($tarpit) {
  29.         sleep($tarpit_delay);
  30.     };
  31.  
  32.  
  33. ##############################################################################
  34. # Check to see if this is a valid user on the destination server
  35.  
  36.     if ($chk_rcpt) {
  37.         if (!&CheckRcptSmtpTcpip($SmtpRcptTo, $smtp_server)) {
  38.             &Message("550 <".$SmtpRcptTo.">... no such user (reported by Mail Server)");
  39.             $SmtpRcptTo = "";
  40.             return;
  41.         };
  42.     };
  43.  
  44.  
  45. ##############################################################################
  46. # Check to see if they are using a colon or percent sign to redirect the recipient
  47.  
  48.     if ((index($SmtpRcptTo, ":") > -1) || (index($SmtpRcptTo, "%") > -1) || (index($SmtpRcptTo, "!") > -1)) {
  49.         &Message("550 : or % or ! redirected recipients are not allowed");
  50.         $SmtpRcptTo = "";
  51.         return;
  52.     };
  53.  
  54.  
  55. ##############################################################################
  56. # Check to see if more than one @ in the RCPT TO field
  57.  
  58.     @at_array = &extract(/\@/, $SmtpRcptTo);
  59.     if (scalar(@at_array) > 1) {
  60.         &Message("550 : Too many @ characters in destination address");
  61.         $SmtpRcptTo = "";
  62.         return;
  63.     };    
  64.  
  65.  
  66. ##############################################################################
  67. # If this host has been accepted for relaying in begin.mml, the perform no more tests
  68.  
  69.     if ($accept) {
  70.         exit;
  71.     };
  72.  
  73. ##############################################################################
  74. # check for email addresses that we always accept mail to
  75.  
  76.     if (scalar(@ok_rcptto) > 0) { 
  77.         if (index(lc($SmtpRcptTo), @ok_rcptto) > -1) { 
  78.             $accept = TRUE;
  79.             &MessageAppend(" (RCPT TO address approved for relaying)");
  80.             exit;
  81.         };
  82.     };
  83.  
  84.  
  85. ##############################################################################
  86. # Determine if the recipient is local or not, and refuse relaying if it is not
  87. #
  88. # Note: in begin.mml the connecting host is checked to see if they are 
  89. # allowed to relay mail, and if they are (at that point), the &Accept command
  90. # is given to stop further checking. If, at this point, a non-local email 
  91. # address is specified as the recipient, then this is a relay request, and 
  92. # is refused.
  93. #
  94. # Note #2: if no local domains are specified in config.mml, then this test 
  95. # is skipped.
  96.  
  97.     if ($reject_relaying) {
  98.         if ((index(lc($SmtpRcptTo), @local_domains) == -1) && (scalar(@local_domains) > 0)) { 
  99.             $smtp_message = "550 Relaying is not allowed";
  100.             $log_message = "550 Relay request denied, and ".$SmtpRcptTo." is not a local domain name.";
  101.             $relay_rejection = TRUE;
  102.             &DefaultRejection;
  103.         };
  104.     };
  105.     
  106. ##############################################################################
  107. # check for email addresses that we do not accept mail to
  108.  
  109.     if (scalar(@no_rcptto) > 0) { 
  110.         if (index(lc($SmtpRcptTo), @no_rcptto) > -1) { 
  111.             $smtp_message = "550 Recipient refused."; 
  112.             $log_message = "550 Recipient is on banned RCPT TO list / matched ".$match; 
  113.             &DefaultRejection;
  114.         };
  115.     };
  116.     
  117.  
  118. ##############################################################################
  119. # Check for maximum number of RCPT TO: allowed
  120.  
  121.     if (scalar(@SmtpRcptTo) >= $max_rcpt_to) {
  122.         $smtp_message = "550 Too many recipients";
  123.         $log_message = "550 Maximum number of recipients was exceeded. Maximum is ".$max_rcpt_to;
  124.         &DefaultRejection;
  125.     };
  126.  
  127.  
  128. ##############################################################################
  129. # Do a gentle tarpitting if too many RCPT TO: are specified
  130.  
  131.     if ($tarpit_rcpt_to_threshold > 0) {
  132.         if (scalar(@SmtpRcptTo) >= $tarpit_rcpt_to_threshold) {
  133.             # the first time we start tarpitting RCPT TO, log it
  134.             if ($first_time_tarpit_rcpt != 1) {
  135.                 $first_time_tarpit_rcpt = 1;
  136.                 &LogMessage("Tarpitting RCPT TO from host: ".$PeerHostname." [".$PeerTcpip."]", "log_refuse");
  137.             };
  138.             sleep(5);
  139.         };
  140.     };
  141.  
  142.  
  143. ##############################################################################
  144. # Check for blank MAIL FROM and more than one recipient
  145.  
  146.     if ($onercpt) {
  147.         if (length($SmtpMailFrom) == 0) {
  148.             if (scalar(@SmtpRcptTo) > 1) {
  149.                 $smtp_message = "550 Message rejected";
  150.                 $log_message = "550 Message rejected because MAIL FROM was blank and more than 1 recipient was specified";
  151.                 &DefaultRejection;
  152.             };
  153.         };
  154.     };
  155.  
  156.  
  157.